﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DbSharp.ConsoleRunner.Parser
{
    public abstract class ArgumentCertificationAttribute : System.Attribute
    {
        private ArgumentCertification certification;

        /// <summary>
        /// Underlying <see cref="ArgumentCertification"/> object.
        /// </summary>
        public ArgumentCertification Certification
        {
            get { return certification; }
        }

        /// <summary>
        /// Creates new instance of ArgumentCertificationAttribute. 
        /// </summary>
        /// <param name="underlyingCertificationType">type of the certification</param>
        /// <param name="constructorParams">parameters of the 
        /// <paramref name="underlyingCertificationType">certification</paramref>constructor</param>
        protected ArgumentCertificationAttribute(Type underlyingCertificationType, params object[] constructorParams)
        {
            if (!underlyingCertificationType.IsSubclassOf(typeof(ArgumentCertification)))
            {
                throw new InvalidOperationException("Parameter underlyingArgumentType must be a subclass of ArgumentCertification.");
            }
            //create certification object of proper type using reflection
            certification = (ArgumentCertification)Activator.CreateInstance(underlyingCertificationType, constructorParams);
        }
    }
}
